package photogcalc;

import photogcalc.common.Constants;
import photogcalc.i18n.I18n;
import photogcalc.i18n.I18nFactory;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.Screen;
import net.sf.microlog.core.Logger;
import net.sf.microlog.core.LoggerFactory;

/**
 * 
 * @author Antti Okkonen
 */
public class AboutView implements CommandListener {
    // Main form and it's items
    private Screen mainForm;
    private Command okCmd;
    	
    private I18n i18n;
    private AboutCommandListener listener;

    private Logger logger = LoggerFactory.getLogger(getClass().getName());
    
    public AboutView(AboutCommandListener listener) {
	this.listener = listener;
        this.i18n = I18nFactory.getI18n(System.getProperty("microedition.locale"));

        // Create UI
        mainForm = createUI();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == okCmd) {
            listener.okCommand();
        } 
        else {
            logger.warn("Unknown command " + c.getLabel());
        }
    }

    protected Form createUI() {
        Form form = new Form(i18n.get("_Ohjelmatiedot") + " - " + Constants.TITLE);

        form.append(Constants.TITLE + "\n");
        form.append(Constants.VERSION + "\n");
        form.append(Constants.RELEASE_DATE + "\n");
        form.append("\n" + Constants.COPYRIGHT + "\n");
        form.append("\n" + Constants.LICENSE + "\n");

        // Add commands to menu
        okCmd = new Command(i18n.get("_Ok"), Command.OK, 2);
        form.addCommand(okCmd);
        form.setCommandListener(this);

        return form;
    }
	
    public Screen getScreen() {
        return mainForm;
    }
}
